package com.whstudio.util.mvc.data;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import com.whstudio.util.xml.CDocument;

public class BeanCollection<T extends BaseVO> extends BaseBean {
	private List<T> list=new ArrayList<T>();
	public void addVO(T e){
		list.add(e);
	}
	public BaseBean getVO(int index){
		return list.get(index);
	}
	public Document toXML(){
		CDocument cdoc=CDocument.getIDocWithRoot(className);
		Element root=cdoc.getDocumentElement();
		root.setAttribute("type", myType.getName());
		for (Iterator<T> iterator = list.iterator(); iterator.hasNext();) {
			T type = iterator.next();
			Document doc=type.toXML();
			//CDocument.getIDoc(doc).viewByText();
			Element e=doc.getDocumentElement();
			Node n=cdoc.adoptNode(e);
			root.appendChild(n);
		}
		cdoc.viewByText();
		return cdoc;
	}
}
